package com.gift.service.Impl;

import com.gift.common.PaGing;
import com.gift.common.ServerResponse;
import com.gift.dao.GameAccountMapper;
import com.gift.dao.GamesMapper;
import com.gift.pojo.GameAccount;
import com.gift.service.GameAccountService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("gameAccountService")
public class GameAccountServiceImpl implements GameAccountService {
    @Resource
    GameAccountMapper gameAccountMapper;
    @Resource
    GamesMapper gamesMapper;



    @Override
    public PaGing getAllBypr(int page, int rows) {
        int raa = (page-1) * rows;
        int total =gameAccountMapper.getCountAll();
        List<GameAccount> gamesList= gameAccountMapper.getAllBypr(raa,rows);
        PaGing paGing= new PaGing(total,gamesList);
        return paGing;
    }

    @Override
    public List<GameAccount> getAll() {
        return gameAccountMapper.getAll();
    }

    @Override
    public ServerResponse insetNewGameAccount(GameAccount newOneGamesAccount) {
        String  GName =gamesMapper.selectByPrimaryKey(newOneGamesAccount.getGid()).getGname();
        newOneGamesAccount.setThegame(GName);
        int res = gameAccountMapper.insert(newOneGamesAccount);
        if(res !=1){
            ServerResponse.createByErrorMessage("新增游戏账号失败");
        }
        return ServerResponse.createBySuccessMessage("新增游戏账号成功");
    }

    @Override
    public ServerResponse updataGameAccount(GameAccount alterGames) {
        String  GName =gamesMapper.selectByPrimaryKey(alterGames.getGid()).getGname();
        alterGames.setThegame(GName);
        int res =gameAccountMapper.updateByPrimaryKeySelective(alterGames);
        if(res !=1){
            ServerResponse.createByErrorMessage("修改游戏账号失败");
        }
        return ServerResponse.createBySuccessMessage("修改游戏账号成功");
    }

    @Override
    public ServerResponse deleteGidList(ArrayList<Integer> deleteIdList) {
        int res =gameAccountMapper.deleteByPrimaryKeyList(deleteIdList);
        if(res <deleteIdList.size()){
            ServerResponse.createByErrorMessage("删除游戏账号失败");
        }
        return ServerResponse.createBySuccessMessage("删除游戏账号成功");
    }
}
